<?php
/**
 *
 * @author xnny
 * @version 
 */

function strtotimeExtend($string)
{
	preg_match('/[\x81-\xfe][\x40-\xfe]/', $string, $time);
	if (empty($time[0]))
	{
		$date = strtotime($string);
	}
	else
	{
		$string = str_replace('(', '', $string);
		$string = str_replace(')', '', $string);
		$string = str_replace('年', '-', $string);
		$string = str_replace('月', '-', $string);
		$string = str_replace('日', '', $string);
		$date = preg_replace('/[\x81-\xfe][\x40-\xfe]/', '', $string);
	}
	return $date;
}
echo strtotimeExtend('2011-6-7 7:56:00(星期六)晴');exit;
#echo strtotimeExtend('2011年05月08日 星期日  02:10');exit;

/*
define('ROOT_CACHE', dirname(__FILE__) . '/cache/');

$rss = 'http://blog.tianya.cn/blogger/rss.asp?BlogID=136608';

$xml = new SimpleXMLElement($rss, LIBXML_NOCDATA, true);

exit;

$xml = simplexml_load_file($rss, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($xml)
{
	die('2222222');
}
else
{
	die('00000000000000000000000000000000000000000000000');
}
die('sds2');

$rss = 'http://blog.tianya.cn/blogger/rss.asp?BlogID=136608';
$fileName = ROOT_CACHE . time() . mt_rand();
#die($fileName);
$rss = file_get_contents($rss);
$rss = iconv('gb2312', 'utf-8//IGNORE', $rss);
$rss = str_replace('<?xml version="1.0" encoding="gb2312"?>', '<?xml version="1.0" encoding="UTF-8"?>', $rss);
file_put_contents($fileName, $rss);
#print_r($rss);exit;

$xml = simplexml_load_file($fileName, 'SimpleXMLElement', LIBXML_NOCDATA);

print_r($xml);exit;
*/
preg_match("/^(http:\/\/)?([^\/]+)/i", "http://www.php.net/index.html", $matchexs); 
$host = $matchexs[2];
#print_r($matchexs);exit;

$s = '<?xml version="1.0" encoding="UTF-8"?>';
$s = '<?xml version="1.0" encoding="hk-8" standalone="yes"?>';
$arr = explode('encoding="', $s);
$arr = explode('"', $arr[1]);
die($arr[0]);
print_r($arr);exit;
$docType = stripos($s, '<?xMl');
$ver = stripos($s, 'version="1.0"');
$char = stripos($s, 'encoding="UtF-8"');
if (is_int($docType) && is_int($ver) && is_int($char))
{
	die('xx33ss');
	var_dump($docType);
	echo "\n";
	var_dump($ver);
	echo "\n";
	var_dump($char);exit;
}
var_dump($docType);
echo "\n";
var_dump($ver);
echo "\n";
var_dump($char);exit;
#preg_match("/^(<?xml version=\"1.0\" encoding=\")?.*(\")?/i", $s, $matches);
preg_match('/encoding=\".*\"(^\s|^\?>)/i', $s, $matches);
print_r($matches);exit;
$s = str_replace('"', '', str_replace('encoding="', '', $matches[0]));
die($s);

if (isset($matches[0]))
{
	die($matches[0]);
}
else
{
	die('xx');
}

exit;

$blog = array();
$post = array();

$rss = 'http://blog.sina.com.cn/rss/1291638571.xml';
$xml = simplexml_load_file($rss, 'SimpleXMLElement', LIBXML_NOCDATA);

$postContentEncoded	= $xml->xpath('/rss/channel/item/content:encoded');
$postDcCreator		= $xml->xpath('/rss/channel/item/dc:creator');
$postInfo			= $xml->xpath('/rss/channel/item');

$blogTitle			= $xml->xpath('/rss/channel/title');
$blogLink			= $xml->xpath('/rss/channel/link');
$blogDescription	= $xml->xpath('/rss/channel/description');
$blogLastBuildDate	= $xml->xpath('/rss/channel/lastBuildDate');

$blog['blogTitle']			= (string)$blogTitle[0];
$blog['blogLink']			= (string)$blogLink[0];
$blog['blogDescription']	= (string)$blogDescription[0];
$blog['blogLastBuildDate']	= (string)$blogLastBuildDate[0];

foreach ($postInfo as $key=>$value)
{
	$post[] = array(
	'postTitle'				=>	(string)$value->title,
	'postLink'				=>	(string)$value->link,
	'postPubDate'			=>	(string)$value->pubDate,
	'postCreator'			=>	(string)$postDcCreator[$key],
	'postContentEncoded'	=>	(string)$postContentEncoded[$key]
	);
}
$blog['post'] = $post;

print_r($blog);
exit;
